<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>

  <div class="box">
    <span>呵呵呵呵</span>
    <p>哈哈哈哈哈哈哈</p>
  </div>

  <script>
    var boxEl = document.querySelector('.box')
    // 通过innerHTML(不推荐)
    boxEl.innerHTML += `
    <h2 class="title">我是标题1</h2>
    `
    setTimeout(function () {
      var titleEl = document.querySelector('.title')
      titleEl.classList.add("active")
    }, 2000)

    // 真实创建一个DOM对象
    var h2El = document.createElement("h2")
    h2El.className = "title"
    h2El.textContent = "我是标题2"
    boxEl.append(h2El)
    // boxEl.prepend(h2El)
    // boxEl.after(h2El)
    // boxEl.before(h2El)
    // boxEl.replaceWith(h2El, "abc")

    // var spanEl = document.querySelector('span')
    // var spanEl = boxEl.children()[0]
    var spanEl = boxEl.querySelector('span')
    spanEl.after(h2El)

  </script>
</body>

</html>